import axios, { type AxiosResponse } from "axios";
import { ElMessage, ElMessageBox } from "element-plus";
import pinia from "@/stores/index";
import { useUserInfoStore } from "../stores/userInfo";

/* 定义response对象的data接口 */
interface ResponseData<T> {
  code: number;
  data: T;
  message: string;
  msg: any;
}


export const api = axios.create({
  timeout: 10000,
  headers: {
    
  }
});

// 配置新建一个 axios 实例
const service = axios.create({
  // baseURL: import.meta.env.VITE_API_URL,
  timeout: 50000,
});

// 添加请求拦截器
service.interceptors.request.use((config: any) => {
  const userStore = useUserInfoStore(pinia);
  if (localStorage.getItem('keytoken')) {
    // console.log('access_token',localStorage.getItem('keytoken'));
    // config.headers.access_token = localStorage.getItem('keytoken');
  }
  return config;
});

// 添加响应拦截器


export default service;
